package com.example.library.mapper;

import com.example.library.entity.Borrow;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 胡绍杆
 * @since 2022-06-16
 */
public interface BorrowMapper extends BaseMapper<Borrow> {
    @Select("SELECT bookname,count(*) AS nums \n" +
            "FROM t_book,t_borrow \n" +
            "WHERE t_book.book_num = t_borrow.book_num \n" +
            "AND (borrow_time BETWEEN #{beginTime} AND #{endTime})\n" +
            "GROUP BY isbn\n" +
            "ORDER BY nums DESC\n" +
            "LIMIT 5")
    public List<Map<String, Object>> getForSecondChart(@Param("beginTime")String beginTime, @Param("endTime")String endTime);

    @Select("SELECT class_name,count(*) AS nums \n" +
            "FROM t_book,t_borrow,t_bookclass \n" +
            "WHERE t_book.book_num = t_borrow.book_num \n" +
            "AND t_book.class_id=t_bookclass.class_id \n" +
            "AND (borrow_time BETWEEN #{beginTime} AND #{endTime})\n" +
            "GROUP BY t_book.class_id\n" +
            "ORDER BY nums DESC")
    public List<Map<String, Object>> getForThirdChart(@Param("beginTime")String beginTime, @Param("endTime")String endTime);

    @Select("SELECT pub,count(*) AS nums \n" +
            "FROM t_book,t_borrow \n" +
            "WHERE t_book.book_num = t_borrow.book_num and (borrow_time BETWEEN #{beginTime} AND #{endTime}) \n" +
            "GROUP BY pub\n" +
            "ORDER BY nums DESC\n" +
            "LIMIT 5")
    public List<Map<String, Object>> getForFourthChart(@Param("beginTime")String beginTime, @Param("endTime")String endTime);
}
